<?php

namespace app\services\exam;

use app\dao\exam\ExamRecordDao;
use app\exceptions\AdminException;
use app\services\BaseService;
use think\App;

class ExamRecordService extends BaseService
{

    public function __construct(ExamRecordDao $dao)
    {
        $this->dao = $dao;
    }

    public function index(array $where)
    {
        return $this->dao->index($where);
    }

    public function createOrUpdate(array $where)
    {
        if ($where['id']) return $this->dao->updateDao($where);
        return $this->dao->create($where);
    }

    public function delete(array $where)
    {
        return $this->dao->deleteDao($where);
    }

    //--------------------------------------------api-------------------------------------------------------
    /*
     * 学生考试记录保存
     */
    public function testRecord(array $where)
    {
        $data = $this->dao->testRecord($where);

        if (!$data) {
            throw new AdminException('保存失败');
        }
        return '保存成功';
    }

    /*
     * 获取学生成绩
     */
    public function getScore(array $where)
    {
        $data = $this->dao->getScore($where);
        $video = $this->dao->getVideoRecord($where);
        $videonum = $this->dao->getVideo($where);
        $rule = $this->dao->getRules($where);
        $videoscore = round(count($video) / count($videonum), 0);
        $score['videoscore'] = $videoscore;
        $score['exam'] = $data;
        $score['rule'] = $rule;
        return $score;

    }

    public function MarkingPapers(array $where)
    {
        return $this->dao->MarkingPapers($where);
    }
}